package com.youlai.boot.gym.controller;

import com.youlai.boot.gym.service.ClassSchedulesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.gym.model.form.ClassSchedulesForm;
import com.youlai.boot.gym.model.query.ClassSchedulesQuery;
import com.youlai.boot.gym.model.vo.ClassSchedulesVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 课程安排前端控制层
 *
 * @author hxc
 * @since 2025-06-01 15:47
 */
@Tag(name = "课程安排接口")
@RestController
@RequestMapping("/api/v1/class-schedules")
@RequiredArgsConstructor
public class ClassSchedulesController  {

    private final ClassSchedulesService classSchedulesService;

    @Operation(summary = "课程安排分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('gym:classSchedules:query')")
    public PageResult<ClassSchedulesVO> getClassSchedulesPage(ClassSchedulesQuery queryParams ) {
        IPage<ClassSchedulesVO> result = classSchedulesService.getClassSchedulesPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增课程安排")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('gym:classSchedules:add')")
    public Result<Void> saveClassSchedules(@RequestBody @Valid ClassSchedulesForm formData ) {
        boolean result = classSchedulesService.saveClassSchedules(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取课程安排表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('gym:classSchedules:edit')")
    public Result<ClassSchedulesForm> getClassSchedulesForm(
        @Parameter(description = "课程安排ID") @PathVariable Long id
    ) {
        ClassSchedulesForm formData = classSchedulesService.getClassSchedulesFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改课程安排")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('gym:classSchedules:edit')")
    public Result<Void> updateClassSchedules(
            @Parameter(description = "课程安排ID") @PathVariable Long id,
            @RequestBody @Validated ClassSchedulesForm formData
    ) {
        boolean result = classSchedulesService.updateClassSchedules(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除课程安排")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('gym:classSchedules:delete')")
    public Result<Void> deleteClassScheduless(
        @Parameter(description = "课程安排ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = classSchedulesService.deleteClassScheduless(ids);
        return Result.judge(result);
    }
}
